package demo;

import java.util.Queue;
import java.util.Stack;

class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;
    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }
    
    public void push(int x) {
        s1.push(x);
    }
    
    public int pop() {
        if(!empty()) {
            if(s2.empty()) {
                int size = s1.size();
                while(size != 0) {
                    int n = s1.pop();
                    s2.push(n);
                    size--;
                }
            }
            return s2.pop();
        }
        return -1;
    }
    
    public int peek() {
        if(!empty()) {
            if(s2.empty()) {
                int size = s1.size();
                while(size != 0) {
                    int n = s1.pop();
                    s2.push(n);
                    size--;
                }
            }
            return s2.peek();
        }
        return -1;
    }
    
    public boolean empty() {
        if(s1.empty() && s2.empty()) {
            return true;
        }
        return false;
    }
}